<?php

/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 16/4/5
 * Time: 下午7:52
 */
class OperationService extends Service{
	
	/**
	 * 踢玩家下线
	 */
	public static function doKick($server, $params){
		if(PubFunc::checkEmpty($params, array('kicktype'))){
			return array('state' => false, 'msg' => '缺少必要参数.');
		}
	
		if(isset($params['kickall'])){
			$params['kickall']  = 1;
			$params['list']     = '';
			$params['kicktype'] = 0;
		}else{
			$params['kickall']  = 0;
			$params['list'] = CommonService::getStringFromMultiLine($params['list']);
		}
	
	
		$api = new ApiService($server);
		return $api->kick($params);
	}
	
	
	/**
	 * 角色禁言
	 */
	public static function doBanChat($server, $params){
		if(PubFunc::checkEmpty($params, array('list'))){
			return array('state' => false, 'msg' => '缺少必要参数.');
		}
		$params['bandate'] = (isset($params['ban_forever']) || empty($params['bandate'])) ? 2000000000 : strtotime($params['bandate']);
		$params['list'] = CommonService::getStringFromMultiLine($params['list']);
		if($params['list'] != ''){
			$params['list'] = '{'.$params['list'].'}';
		}
		unset($params['ban_forever']);
	
		$api = new ApiService($server);
		return $api->banChat($params);
	}
	
	/**
	 * 账号封禁
	 */
    public static function doBan($server, $params){
        if(PubFunc::checkEmpty($params, array('bantype','list'))){
            return array('state' => false, 'msg' => '缺少必要参数.');
        }
        $params['bandate'] = (isset($params['ban_forever']) || empty($params['bandate'])) ? 2000000000 : strtotime($params['bandate']);
        $params['list'] = CommonService::getStringFromMultiLine($params['list']);
        if($params['list'] != ''){
        	$params['list'] = '{'.$params['list'].'}';
        }
        unset($params['ban_forever']);

        $api = new ApiService($server);
        return $api->ban($params);
    }

    
    
    public static function doClear($server, $params){
        if(PubFunc::checkEmpty($params, array('roleType', 'ClearType', 'data'))){
            return array('state' => false, 'msg' => '缺少必要参数.');
        }

        $params['data'] = CommonService::getStringFromMultiLine($params['data']);

        $api = new ApiService($server);
        return $api->clear($params);
    }

    public static function doDeduct($params){
        if($params['type'] == 'item'){
            $args = array(
                'roleName'      => $params['role_name'],
                'propId'        => $params['prop_id'],
                'onlyId'        => $params['only_id'],
                'propNum'       => $params['prop_num'],
            );
            $result = ApiService::delProp($args);
        }else if($params['type'] == 'gold'){
            $args = array(
                'roleName'    => $params['role_name'],
                'goldId'    => $params['gold_id'],
                'goldNum'   => $params['gold_num']
            );
            $result = ApiService::delGold($args);
        }

        return $result;
    }

    public static function banType(){
        return array(
            '1'        => '按账号封禁',
            '2'       => '按角色名封禁',
            '3'       => '按设备号封禁',
            '4'         => '按IP封禁',
        );
    }

    public static function channelType(){
        return array(
            '0' => '0.所有频道',
//            '1' => '1.世界频道',
//            '2' => '2.个人频道',
//            '3' => '3.系统频道',
//            '4' => '4.队伍频道',
//            '5' => '5.帮会频道',
//            '6' => '6.喇叭频道'
        );
    }

}